function varargout = hvo(varargin)
% HVO M-file for hvo.fig
%      HVO, by itself, creates a new HVO or raises the existing
%      singleton*.
%
%      H = HVO returns the handle to a new HVO or the handle to
%      the existing singleton*.
%
%      HVO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in HVO.M with the given input arguments.
%
%      HVO('Property','Value',...) creates a new HVO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before hvo_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to hvo_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
%
% HVO is the horizontal velocity overlay gui.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Name: rslice-0_9_2 $
% $Id: hvo.m,v 1.3 2005/06/22 13:21:54 jevans Exp $
% AUTHOR:  johnevans@acm.org
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Edit the above text to modify the response to help hvo

% Last Modified by GUIDE v2.5 10-Jun-2005 08:25:25

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @hvo_OpeningFcn, ...
                   'gui_OutputFcn',  @hvo_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before hvo is made visible.
function hvo_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to hvo (see VARARGIN)

% Choose default command line output for hvo
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes hvo wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = hvo_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on slider movement.
function hvo_arrow_scale_slider_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_arrow_scale_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function hvo_arrow_scale_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_arrow_scale_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function slider9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_arrow_scale_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
return



function hvo_scale_string_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_scale_string (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of hvo_scale_string as text
%        str2double(get(hObject,'String')) returns contents of hvo_scale_string as a double


	%
	% Retrieve the scale value from the edit widget.
	hvo_handles = guihandles ( hObject );
	arrow_scale = get ( hvo_handles.hvo_scale_string, 'String' );
	arrow_scale = str2double ( arrow_scale );

	if isnan ( arrow_scale )

		%
		% Ok, the user did something bad.  Since the edit widget
		% no longer has a valid string, the best alternative is to
		% return it to the string representation of the value 
		% currently held by the slider.
		arrow_scale = get ( hvo_handles.hvo_scale_slider, 'Value' );
		arrow_scale_string = sprintf ( '%.2f', arrow_scale );
		set ( hvo_handles.hvo_scale_string, 'String', arrow_scale_string );
		return

	end

	%
	% Check to make sure that the value is reasonable.  If not,
	% readjust it.
	slider_max = get ( hvo_handles.hvo_scale_slider, 'Max' );
	if ( arrow_scale > slider_max )
		arrow_scale = slider_max;
		arrow_scale_string = sprintf ( '%.2f', arrow_scale );
		set ( hvo_handles.hvo_scale_string, 'String', arrow_scale_string );
	end

	slider_min = get ( hvo_handles.hvo_scale_slider, 'Min' );
	if ( arrow_scale < slider_min )
		arrow_scale = slider_min;
		arrow_scale_string = sprintf ( '%.2f', arrow_scale );
		set ( hvo_handles.hvo_scale_string, 'String', arrow_scale_string );
	end


	%
	% Make the slider widget match the scale value given by the edit widget.
	set ( hvo_handles.hvo_scale_slider, 'Value', arrow_scale );


	%
	% And redraw the arrows
	hvo_data = guidata ( hObject );
	rslice_object = hvo_data.parent;
	rslice_velocity_overlay_redraw ( rslice_object );


% --- Executes during object creation, after setting all properties.
function hvo_scale_string_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_scale_string (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function hvo_subsample_string_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_subsample_string (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of hvo_subsample_string as text
%        str2double(get(hObject,'String')) returns contents of hvo_subsample_string as a double


% --- Executes during object creation, after setting all properties.
function hvo_subsample_string_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_subsample_string (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function slider8_Callback(hObject, eventdata, handles)
% hObject    handle to slider8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function hvo_arrow_subsample_slider_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_arrow_subsample_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function hvo_arrow_subsample_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_arrow_subsample_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function hvo_red_slider_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_red_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

	%
	% Retrieve the value from the slider widget.
	handles = guihandles ( hObject );
	slider_value = get ( hObject, 'Value' );

	%
	% Set the text (two digits of precision should be sufficient) to match.
	slider_text = sprintf ( 'R:  %.2f', slider_value );
	set ( handles.hvo_red_text, 'String', slider_text );

	%
	% And redraw the arrows
	hvo_data = guidata ( hObject );
	rslice_object = hvo_data.parent;

	rslice_velocity_overlay_redraw ( rslice_object );

	return


% --- Executes during object creation, after setting all properties.
function hvo_red_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_red_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function hvo_green_slider_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_green_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


	%
	% Retrieve the value from the slider widget.
	handles = guihandles ( hObject );
	slider_value = get ( hObject, 'Value' );

	%
	% Set the text (two digits of precision should be sufficient) to match.
	slider_text = sprintf ( 'G:  %.2f', slider_value );
	set ( handles.hvo_green_text, 'String', slider_text );


	%
	% And redraw the arrows
	hvo_data = guidata ( hObject );
	rslice_object = hvo_data.parent;
	rslice_velocity_overlay_redraw ( rslice_object );

	return


% --- Executes during object creation, after setting all properties.
function hvo_green_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_green_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function hvo_blue_slider_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_blue_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

	%
	% Retrieve the value from the slider widget.
	handles = guihandles ( hObject );
	slider_value = get ( hObject, 'Value' );

	%
	% Set the text (two digits of precision should be sufficient) to match.
	slider_text = sprintf ( 'B:  %.2f', slider_value );
	set ( handles.hvo_blue_text, 'String', slider_text );

	%
	% And redraw the arrows
	hvo_data = guidata ( hObject );
	rslice_object = hvo_data.parent;
	rslice_velocity_overlay_redraw ( rslice_object );

	return



% --- Executes during object creation, after setting all properties.
function hvo_blue_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_blue_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on button press in show_hide_arrows_toggle.
function show_hide_arrows_toggle_Callback(hObject, eventdata, handles)
% hObject    handle to show_hide_arrows_toggle (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of show_hide_arrows_toggle

	%
	% We don't need to do much, just invoke the redraw function which
	% takes care of it.
	hvo_data = guidata ( hObject );
	rslice_object = hvo_data.parent;
	rslice_velocity_overlay_redraw ( rslice_object );


	return


% --- Executes on slider movement.
function hvo_scale_slider_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_scale_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

	hvo_handles = guihandles ( hObject );

	%
	% Get the value from the slider and transfer it to the edit text widget.
	arrow_scale = get ( hvo_handles.hvo_scale_slider, 'Value' );
	arrow_scale = sprintf ( '%.2f', arrow_scale );
	set ( hvo_handles.hvo_scale_string, 'String', arrow_scale );


	%
	% and finally redraw the arrows
	hvo_data = guidata ( hObject );
	rslice_object = hvo_data.parent;
	rslice_velocity_overlay_redraw ( rslice_object );

	return


% --- Executes during object creation, after setting all properties.
function hvo_scale_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_scale_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function hvo_subsample_slider_Callback(hObject, eventdata, handles)
% hObject    handle to hvo_subsample_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

	hvo_handles = guihandles ( hObject );


	%
	% Get the value from the slider and transfer it to the edit text widget.
	sample_rate = get ( hvo_handles.hvo_subsample_slider, 'Value' );
	sample_rate = num2str ( round ( sample_rate ) );
	set ( hvo_handles.hvo_subsample_string, 'String', sample_rate );


	%
	% and finally redraw the arrows
	hvo_data = guidata ( hObject );
	rslice_object = hvo_data.parent;
	rslice_velocity_overlay_redraw ( rslice_object );

	return


% --- Executes during object creation, after setting all properties.
function hvo_subsample_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to hvo_subsample_slider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function slider12_Callback(hObject, eventdata, handles)
% hObject    handle to slider12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function slider12_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


